package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusSensor;
import com.ruoyi.business.service.IBusSensorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 易损耗传感器Controller
 * 
 * @author asher
 * @date 2021-10-14
 */
@RestController
@RequestMapping("/business/sensor")
public class BusSensorController extends BaseController
{
    @Autowired
    private IBusSensorService busSensorService;

    /**
     * 查询易损耗传感器列表
     */
    @PreAuthorize("@ss.hasPermi('business:sensor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusSensor busSensor)
    {
        startPage();
        List<BusSensor> list = busSensorService.selectBusSensorList(busSensor);
        return getDataTable(list);
    }

    /**
     * 导出易损耗传感器列表
     */
    @PreAuthorize("@ss.hasPermi('business:sensor:export')")
    @Log(title = "易损耗传感器", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusSensor busSensor)
    {
        List<BusSensor> list = busSensorService.selectBusSensorList(busSensor);
        ExcelUtil<BusSensor> util = new ExcelUtil<BusSensor>(BusSensor.class);
        return util.exportExcel(list, "易损耗传感器数据");
    }

    /**
     * 获取易损耗传感器详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:sensor:query')")
    @GetMapping(value = "/{sensorId}")
    public AjaxResult getInfo(@PathVariable("sensorId") Long sensorId)
    {
        return AjaxResult.success(busSensorService.selectBusSensorBySensorId(sensorId));
    }

    /**
     * 新增易损耗传感器
     */
    @PreAuthorize("@ss.hasPermi('business:sensor:add')")
    @Log(title = "易损耗传感器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusSensor busSensor)
    {
        return toAjax(busSensorService.insertBusSensor(busSensor));
    }

    /**
     * 修改易损耗传感器
     */
    @PreAuthorize("@ss.hasPermi('business:sensor:edit')")
    @Log(title = "易损耗传感器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusSensor busSensor)
    {
        return toAjax(busSensorService.updateBusSensor(busSensor));
    }

    /**
     * 删除易损耗传感器
     */
    @PreAuthorize("@ss.hasPermi('business:sensor:remove')")
    @Log(title = "易损耗传感器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sensorIds}")
    public AjaxResult remove(@PathVariable Long[] sensorIds)
    {
        return toAjax(busSensorService.deleteBusSensorBySensorIds(sensorIds));
    }
}
